import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import index from '../views/index.vue'
import movie from '@/views/movie'
import cinema from '@/views/cinema'
import login from '@/views/Login'
import seat from '@/views/seat'
import hotShow from '@/views/hotShow'
import waitShow from '@/views/waitShow'
import search from '@/views/search'
import order from '@/views/order'
import notice from '@/views/notice/notice'
import noticeIndex from '@/views/notice/index'
import layoutTable from '@/views/layoutTable'
import register from '@/views/register'
import basicInfo from '@/views/person/basicInfo'
import personIndex from '@/views/person/index'
import myOrder from '@/views/person/myOrder'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    redirect:"/index",
    children:[
      {
      path: '/index',
      name:'index',
      component:index
    },
      {
        path:'/movie',
        name:'movie',
        component:movie,
        redirect:'/hotShow',
        children:[
          {
           path:'/hotShow',
           name:'movie',
          component:hotShow
        },
        {
          path:'/waitShow',
          name:'movie',
          component:waitShow
        }
         
        ]
      },
      {
        path:'/cinema',
        name:'cinema',
        component:cinema
      },
      {
        path:'/seat',
        name:'seat',
        component:seat
      },
      {
        path:'/search',
        name:'search',
        component:search
      },
      {
        path:'/order',
        name:'order',
        component:order,
      },
      {
        path:'/notice',
        component:noticeIndex,
        redirect:'/notice/notice/',
        children:[
          {
            path:'/notice/notice/',
            component:notice
          }
        ]
      },
      {
        path:'/layout',
        name:'layout',
        component:layoutTable
      },
      {
        path:'/person',
        component:personIndex,
        children:[
          {
            path:'/basicInfo',
            name:basicInfo,
            component:basicInfo
          },
          {
            path:'/myOrder',
            name:'myOrder',
            component:myOrder
          }
        ]
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: login,
  },
  {
    path:'/register',
    component:register
  },

 
]


const router = new VueRouter({
  routes,
  //每次路由跳转时滚动条回到最上方
  scrollBehavior(to, from,savedPosition) {
    return {
      x: 0,
      y: 0
    }
  }
})

router.beforeEach((to, from, next) => {
  console.log(to)
  console.log(from)
  console.log(to.meta.keepAlive)
  console.log(to.path)
  if (to.path=="/order") {
    to.meta.keepAlive = true;
  } 
  else {
    to.meta.keepAlive = false;
  }
  // 如果用户未能验证身份，则 `next` 会被调用两次
  next()
})

export default router
